home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / driv-standard / level-0 / pk.tex (.txt) < prev    next >
LaTeX Document  |  1991-08-07  |  27KB  |  507 lines

  1. % $Id: pk.tex,v 2.3.1.1 1991/08/08 16:21:26 schrod Released schrod $
  2. %------------------------------------------------------------
  3. % taken from PKtype 2.3
  4. % definition of PK format
  5. % LaTeX markup
  6. % $Log: pk.tex,v $
  7. % Revision 2.3.1.1  1991/08/08  16:21:26  schrod
  8. % CHANGES BY DON HOSEK:
  9. %  -- Inserted \subsection's.
  10. %  -- Deleted WEB defines.
  11. %  -- `e.g.' now in italics, to be consistent with the rest of the
  12. %     standard.
  13. % CHANGES BY JOACHIM SCHROD:
  14. %  -- Changed \bigbreak between WEB sections to \medbreak.
  15. %  -- Added + signs to length specifications in \cmd tags, to show that
  16. %     the param is signed.
  17. %  -- Make formulas look more `math-like' and less `Pascal-like.'
  18. %  -- Example and `packed number decoding algorithm' as figures.
  19. %  -- Exchange this crude example picture with the explicite halign with
  20. %     an environment for drawing letter examples.
  21. % Revision 2.3  1990/11/15  19:03:50  schrod
  22. % integrated changes of 18 Nov 89 by Don: The weight of bits were specified
  23. % wrong and a few phrases were changed.
  24. %    Please note that these changes make version 2.3, even if this is not
  25. % noted in the version history of PKtype. But the version change was made
  26. % both on the title page and in the banner message.
  27. % Revision 2.2.1.2  90/07/17  00:00:00  schrod
  28. % two \& were forgotten.
  29. % Revision 2.2.1.1  90/07/16  00:00:00  schrod
  30. % adapted to PKtype change of Don (Hosek? Knuth? -- 21 Oct 89).
  31. % changed \& to \res in documentation parts.
  32. % appended \endinput.
  33. % Revision 2.2  90/07/04  00:00:00  schrod
  34. % extracted from PKtype 2.2
  35. \section{Packed File Format}
  36. \label{pk-format}
  37. \subsection{Introduction}
  38. The packed file format is a compact representation of the data
  39. contained in a \str{GF} file. The information content is the same,
  40. but packed (\str{PK}) files are almost always less than half the size
  41. of their \str{GF} counterparts. They are also easier to convert into
  42. a raster representation because they do not have a profusion of
  43. \id{paint}, \id{skip}, and \id{new\_row} commands to be separately
  44. interpreted. In addition, the \str{PK} format expressedly forbids
  45. \res{special} commands within a character. The minimum bounding box
  46. for each character is explicit in the format, and does not need to be
  47. scanned for as in the \str{GF} format. Finally, the width and
  48. escapement values are combined with the raster information into
  49. character ``packets,'' making it simpler in many cases to process a
  50. character.
  51. A \str{PK} file is organized as a stream of 8-bit bytes. At times,
  52. these bytes might be split into 4-bit nybbles or single bits, or
  53. combined into multiple byte parameters. When bytes are split into
  54. smaller pieces, the `first' piece is always the most significant of
  55. the byte. For instance, the first bit of a byte is the bit with value
  56. 128; the first nybble can be found by dividing a byte by 16.
  57. Similarly, when bytes are combined into multiple byte parameters, the
  58. first byte is the most significant of the parameter. If the parameter
  59. is signed, it is represented by two's-complement notation.
  60. The set of possible eight-bit values is separated into two sets,
  61. those that introduce a character definition, and those that do not.
  62. The values that introduce a character definition range from 0 to 239;
  63. byte values above 239 are interpreted as commands. Bytes that
  64. introduce character definitions are called flag bytes, and various
  65. fields within the byte indicate various things about how the
  66. character definition is encoded. Command bytes have zero or more
  67. parameters, and can never appear within a character definition or
  68. between parameters of another command, where they would be interpeted
  69. as data.
  70. A \str{PK} file consists of a preamble, followed by a sequence of one
  71. or more character definitions, followed by a postamble. The preamble
  72. command must be the first byte in the file, followed immediately by
  73. its parameters. Any number of character definitions may follow, and
  74. any command but the preamble command and the postamble command may
  75. occur between character definitions. The very last command in the
  76. file must be the postamble.
  77. \medbreak
  78. The packed file format is intended to be easy to read and interpret
  79. by device drivers. The small size of the file reduces the
  80. input/output overhead each time a font is loaded. For those drivers
  81. that load and save each font file into memory, the small size also
  82. helps reduce the memory requirements. The length of each character
  83. packet is specified, allowing the character raster data to be loaded
  84. into memory by simply counting bytes, rather than interpreting each
  85. command; then, each character can be interpreted on a demand basis.
  86. This also makes it possible for a driver to skip a particular
  87. character quickly if it knows that the character is unused.
  88. \subsection{Summary of {\tt PK} commands}
  89. First, the command bytes will be presented; then the format of the
  90. character definitions will be defined. Eight of the possible sixteen
  91. commands (values 240 through 255) are currently defined; the others
  92. are reserved for future extensions. The commands are listed below.
  93. Each command is specified by its symbolic name ({\it e.g.},
  94. \id{pk\_no\_op}), its opcode byte, and any parameters. The parameters
  95. are followed by a bracketed number telling how many bytes they
  96. occupy, with the number preceded by a plus sign if it is a signed
  97. quantity. (Four byte quantities are always signed, however.)
  98. \cmd \id{pk\_xxx1} 240, k[1] x[k].
  99.  This command is undefined in general; it functions as a $(k+2)$-byte
  100. \id{no\_op} unless special \str{PK}-reading programs are being used.
  101. \MF\ generates \id{xxx} commands when encountering a \res{special}
  102. string. It is recommended that $x$ be a string having the form of a
  103. keyword followed by possible parameters relevant to that keyword.
  104. \cmd \id{pk\_xxx2} 241, k[2] x[k].
  105.  Like \id{pk\_xxx1}, but $0\le k<65536$.
  106. \cmd \id{pk\_xxx3} 242, k[3] x[k].
  107.  Like \id{pk\_xxx1}, but $0\le k<2^{24}$. \MF\ uses this when sending
  108. a \res{special} string whose length exceeds~255.
  109. \cmd \id{pk\_xxx4} 243, k[4] x[k].
  110.  Like \id{pk\_xxx1}, but $k$ can be ridiculously large; $k$ musn't be
  111. negative.
  112. \cmd \id{pk\_yyy} 244, y[4].
  113.  This command is undefined in general; it functions as a five-byte
  114. \id{no\_op} unless special \str{PK} reading programs are being used.
  115. \MF\ puts \id{scaled} numbers into \id{yyy}'s, as a result of
  116. \res{numspecial} commands; the intent is to provide numeric
  117. parameters to \id{xxx} commands that immediately precede.
  118. \cmd \id{pk\_post} 245,.
  119.  Beginning of the postamble. This command is followed by enough
  120. \id{pk\_no\_op} commands to make the file a multiple of four bytes
  121. long. Zero through three bytes are usual, but any number is allowed.
  122. This should make the file easy to read on machines that pack four
  123. bytes to a word.
  124. \cmd \id{pk\_no\_op} 246,.
  125.  No operation, do nothing. Any number of \id{pk\_no\_op}'s may appear
  126. between \str{PK} commands, but a \id{pk\_no\_op} cannot be inserted
  127. between a command and its parameters, between two parameters, or
  128. inside a character definition.
  129. \cmd \id{pk\_pre} 247, i[1] k[1] x[k] \id{ds}[4] \id{cs}[4] \id{hppp}[4] %
  130. \id{vppp}[4].
  131.  Preamble command. Here, $i$ is the identification byte of the file,
  132. currently equal to 89. The string $x$ is merely a comment, usually
  133. indicating the source of the \str{PK} file. The parameters \id{ds}
  134. and \id{cs} are the design size of the file in $1/2^{20}$ points, and
  135. the checksum of the file, respectively. The checksum should match the
  136. \str{TFM} file and the \str{GF} files for this font. Parameters
  137. \id{hppp} and \id{vppp} are the ratios of pixels per point,
  138. horizontally and vertically, multiplied by $2^{16}$; they can be used
  139. to correlate the font with specific device resolutions,
  140. magnifications, and ``at sizes.''
  141. \subsection{Packing algorithms}
  142. The \str{PK} format has two conflicting goals: to pack character
  143. raster and size information as compactly as possible, while retaining
  144. ease of translation into raster and other forms. A suitable
  145. compromise was found in the use of run-encoding of the raster
  146. information. Instead of packing the individual bits of the character,
  147. we instead count the number of consecutive `black' or `white' pixels
  148. in a horizontal raster row, and then encode this number. Run counts
  149. are found for each row from left to right, traversing rows from the
  150. top to bottom. This is essentially the way the \str{GF} format works.
  151. Instead of presenting each row individually, however, we concatenate
  152. all of the horizontal raster rows into one long string of pixels, and
  153. encode this row. With knowledge of the width of the bit-map, the
  154. original character glyph can easily be reconstructed. In addition, we
  155. do not need special commands to mark the end of one row and the
  156. beginning of the next.
  157. Next, we place the burden of finding the minimum bounding box on the
  158. part of the font generator, since the characters will usually be used
  159. much more often than they are generated. The minimum bounding box is
  160. the smallest rectangle that encloses all `black' pixels of a
  161. character. We also eliminate the need for a special end of character
  162. marker, by supplying exactly as many bits as are required to fill the
  163. minimum bounding box, from which the end of the character is
  164. implicit.
  165. Let us next consider the distribution of the run counts. Analysis of
  166. several dozen pixel files at 300 dots per inch yields a distribution
  167. peaking at four, falling off slowly until ten, then a bit more
  168. steeply until twenty, and then asymptotically approaching the
  169. horizontal. Thus, the great majority of our run counts will fit in a
  170. four-bit nybble. The eight-bit byte is attractive for our run-counts,
  171. as it is the standard on many systems; however, the wasted four bits
  172. in the majority of cases seem a high price to pay. Another
  173. possibility is to use a Huffman-type encoding scheme with a variable
  174. number of bits for each run-count; this was rejected because of the
  175. overhead in fetching and examining individual bits in the file. Thus,
  176. the character raster definitions in the \str{PK} file format are
  177. based on the four-bit nybble.
  178. \medbreak
  179. An analysis of typical pixel files yielded another interesting
  180. statistic: Fully 37\,\% of the raster rows were duplicates of the
  181. previous row. Thus, the \str{PK} format allows the specification of
  182. repeat counts, which indicate how many times a horizontal raster row
  183. is to be repeated. These repeated rows are taken out of the character
  184. glyph before individual rows are concatenated into the long string of
  185. pixels.
  186. For elegance, we disallow a run count of zero. The case of a null
  187. raster description should be gleaned from the character width and
  188. height being equal to zero, and no raster data should be read. No
  189. other zero counts are ever necessary. Also, in the absence of repeat
  190. counts, the repeat value is set to be zero (only the original row is
  191. sent.)  If a repeat count is seen, it takes effect on the current
  192. row. The current row is defined as the row on which the first pixel
  193. of the next run count will lie. The repeat count is set back to zero
  194. when the last pixel in the current row is seen, and the row is sent
  195. This poses a problem for entirely black and entirely white rows,
  196. however. Let us say that the current row ends with four white pixels,
  197. and then we have five entirely empty rows, followed by a black pixel
  198. at the beginning of the next row, and the character width is ten
  199. pixels. We would like to use a repeat count, but there is no legal
  200. place to put it. If we put it before the white run count, it will
  201. apply to the current row. If we put it after, it applies to the row
  202. with the black pixel at the beginning. Thus, entirely white or
  203. entirely black repeated rows are always packed as large run counts
  204. (in this case, a white run count of 54) rather than repeat counts.
  205. \medbreak
  206. Now we turn our attention to the actual packing of the run counts and
  207. repeat counts into nybbles. There are only sixteen possible nybble
  208. values. We need to indicate run counts and repeat counts. Since the
  209. run counts are much more common, we will devote the majority of the
  210. nybble values to them. We therefore indicate a repeat count by a
  211. nybble of 14 followed by a packed number, where a packed number will
  212. be explained later. Since the repeat count value of one is so common,
  213. we indicate a repeat one command by a single nybble of 15. A 14
  214. followed by the packed number 1 is still legal for a repeat one
  215. count. The run counts are coded directly as packed numbers.
  216. For packed numbers, therefore, we have the nybble values 0 through
  217. 13. We need to represent the positive integers up to, say,
  218. $2^{31}-1$. We would like the more common smaller numbers to take
  219. only one or two nybbles, and the infrequent large numbers to take
  220. three or more. We could therefore allocate one nybble value to
  221. indicate a large run count taking three or more nybbles. We do this
  222. with the value 0.
  223. \medbreak
  224. We are left with the values 1 through 13. We can allocate some of
  225. these, say \id{dyn\_f}, to be one-nybble run counts. These will work
  226. for the run counts $1, \ldots, \id{dyn\_f}$. For subsequent run counts, we
  227. will use a nybble greater than \id{dyn\_f}, followed by a second
  228. nybble, whose value can run from 0 through 15. Thus, the two-nybble
  229. values will run from
  230. $\id{dyn\_f}+1, \ldots, (13-\id{dyn\_f})\ast16+\id{dyn\_f}$. We have our
  231. definition of large run count values now, being all counts greater
  232. than $(13-\id{dyn\_f})\ast16+\id{dyn\_f}$.
  233. We can analyze our several dozen pixel files and determine an optimal
  234. value of \id{dyn\_f}, and use this value for all of the characters.
  235. Unfortunately, values of \id{dyn\_f} that pack small characters well
  236. tend to pack the large characters poorly, and values that pack large
  237. characters well are not efficient for the smaller characters. Thus,
  238. we choose the optimal \id{dyn\_f} on a character basis, picking the
  239. value that will pack each individual character in the smallest number
  240. of nybbles. Legal values of \id{dyn\_f} run from 0 (with no
  241. one-nybble run counts) to 13 (with no two-nybble run counts).
  242. \medbreak
  243. Our only remaining task in the coding of packed numbers is the large
  244. run counts. We use a scheme suggested by {\sc D.\,E.~Knuth} that
  245. simply and elegantly represents arbitrarily large values. The general
  246. scheme to represent an integer $i$ is to write its hexadecimal
  247. representation, with leading zeros removed. Then we count the number
  248. of digits, and prepend one less than that many zeros before the
  249. hexadecimal representation. Thus, the values from one to fifteen
  250. occupy one nybble; the values sixteen through 255 occupy three, the
  251. values 256 through 4095 require five, etc.
  252. For our purposes, however, we have already represented the numbers
  253. one through $(13-\id{dyn\_f})\ast16+\id{dyn\_f}$. In addition, the
  254. one-nybble values have already been taken by our other commands,
  255. which means that only the values from sixteen up are available to us
  256. for long run counts. Thus, we simply normalize our long run counts,
  257. by subtracting $(13-\id{dyn\_f})\ast16+\id{dyn\_f}+1$ and adding 16,
  258. and then we represent the result according to the scheme above.
  259. \subsection{Decoding {\tt PK} files}
  260. The final algorithm for decoding the run counts based on the above
  261. scheme might look like the Pascal routine in
  262. figure~\ref{fig:pk_packed_num}, assuming that a procedure called
  263. \id{pk\_nyb} is available to get the next nybble from the file, and
  264. assuming that the global \id{repeat\_count} indicates whether a row
  265. needs to be repeated. Note that this routine is recursive, but since
  266. a repeat count can never directly follow another repeat count, it can
  267. only be recursive to one level.
  268. \begin{figure*}
  269. \begin{webprog}
  270. \P\4\&{function}\1\  \37\\{pk\_packed\_num}: \37\\{integer};\6
  271. \4\&{var} \37$\|i,\39\|j$: \37\\{integer};\2\6
  272. \&{begin}\5
  273. $\|i\K\\{get\_nyb}$;\6
  274. \&{if} $\|i=0$ \1\&{then}\6
  275. \&{begin}\6
  276. \1\&{repeat}\5
  277. $\|j\K\\{get\_nyb}$;\5
  278. $\\{incr}(\|i)$;\6
  279. \4\&{until}\5
  280. $\|j\I0$;\2\6
  281. \&{while} $\|i>0$ \1\&{do}\6
  282. \&{begin}\5
  283. $\|j\K\|j\ast16+\\{get\_nyb}$;\5
  284. $\\{decr}(\|i)$;\6
  285. \&{end};\2\6
  286. $\\{pk\_packed\_num}\K\|j-15+(13-\\{dyn\_f})\ast16+\\{dyn\_f}$;\6
  287. \&{end}\6
  288. \4\&{else} \&{if} $\|i\L\\{dyn\_f}$ \1\&{then}\5
  289. $\\{pk\_packed\_num}\K\|i$\6
  290. \4\&{else} \&{if} $\|i<14$ \1\&{then}\5
  291. $\\{pk\_packed\_num}\K(\|i-\\{dyn\_f}-1)\ast16+\\{get\_nyb}+\\{dyn\_f}+1$\6
  292. \4\&{else} \&{begin}\6
  293. \&{if} $\\{repeat\_count}\I0$ \1\&{then}\5
  294. $\\{abort}(\.{\'Second\ repeat\ count\ for\ this\ row!\'})$;\2\6
  295. $\\{repeat\_count}\K1$;\C{prevent recursion more than one level}\6
  296. \&{if} $\|i=14$ \1\&{then}\5
  297. ! $\\{repeat\_count}\K\\{pk\_packed\_num}$;\2\6
  298. $\\{send\_out}(\\{true},\39\\{repeat\_count})$;\5
  299. $\\{pk\_packed\_num}\K\\{pk\_packed\_num}$;\6
  300. \&{end};\2\2\2\6
  301. \&{end};\par
  302. \end{webprog}
  303. \caption{Algorithm for decoding run counts in a \protect\str{PK} file}
  304. \label{fig:pk_packed_num}
  305. \end{figure*}
  306. \medbreak
  307. For low resolution fonts, or characters with `gray' areas, run
  308. encoding can often make the character many times larger. Therefore,
  309. for those characters that cannot be encoded efficiently with run
  310. counts, the \str{PK} format allows bit-mapping of the characters.
  311. This is indicated by a \id{dyn\_f} value of 14. The bits are packed
  312. tightly, by concatenating all of the horizontal raster rows into one
  313. long string, and then packing this string eight bits to a byte. The
  314. number of bytes required can be calculated by $\lfloor
  315. (\id{width}\ast\id{height}+7) / 8 \rfloor$. This format should only
  316. be used when packing the character by run counts takes more bytes
  317. than this, although, of course, it is legal for any character. Any
  318. extra bits in the last byte should be set to zero.
  319. \medbreak
  320. At this point, we are ready to introduce the format for a character
  321. descriptor. It consists of three parts: a flag byte, a character
  322. preamble, and the raster data. The most significant four bits of the
  323. flag byte yield the \id{dyn\_f} value for that character. (Notice
  324. that only values of 0 through 14 are legal for \id{dyn\_f}, with 14
  325. indicating a bit mapped character; thus, the flag bytes do not
  326. conflict with the command bytes, whose upper nybble is always 15.)
  327. The next bit (with weight 8) indicates whether the first run count
  328. is a black count or a white count, with a one indicating a black
  329. count. For bit-mapped characters, this bit should be set to a zero.
  330. The next bit (with weight 4) indicates whether certain later
  331. parameters (referred to as size parameters) are given in one-byte or
  332. two-byte quantities, with a one indicating that they are in two-byte
  333. quantities. The last two bits are concatenated on to the beginning of
  334. the packet-length parameter in the character preamble, which will be
  335. explained below.
  336. However, if the last three bits of the flag byte are all set
  337. (normally indicating that the size parameters are two-byte values and
  338. that a 3 should be prepended to the length parameter), then a long
  339. format of the character preamble should be used instead of one of the
  340. short forms.
  341. Therefore, there are three formats for the character preamble; the
  342. one that is used depends on the least significant three bits of the
  343. flag byte. If the least significant three bits are in the range zero
  344. through three, the short format is used. If they are in the range
  345. four through six, the extended short format is used. Otherwise, if
  346. the least significant bits are all set, then the long form of the
  347. character preamble is used. The preamble formats are explained below.
  348. \begin{description}
  349. \let\sp=\ %                % save meaning of `\ ' in this env
  350. \everymath{\def\ {\allowbreak\sp}}    % allow line break within math list
  351. \item[Short form]
  352.  $\id{flag}[1]\ \id{pl}[1]\ \id{cc}[1]\ \id{tfm}[3]\
  353.     \id{dm}[1]\ w[1]\ h[1]\ \id{hoff}[+1]\ \id{voff}[+1]$.\\
  354.  If this format of the character preamble is used, the above
  355. parameters must all fit in the indicated number of bytes, signed or
  356. unsigned as indicated. Almost all of the standard \TeX\ font
  357. characters fit; the few exceptions are fonts such as \str{cminch}.
  358. \item[Extended short form]
  359.  $\id{flag}[1]\ \id{pl}[2]\ \id{cc}[1]\ \id{tfm}[3]\ \id{dm}[2]\ w[2]\ h[2]\ 
  360.     \id{hoff}[+2]\ \id{voff}[+2]$.\\
  361.  Larger characters use this extended format.
  362. \item[Long form]
  363.  $\id{flag}[1]\ \id{pl}[4]\ \id{cc}[4]\ \id{tfm}[4]\ \id{dx}[4]\ \id{dy}[4]\
  364.     w[4]\ h[4]\ \id{hoff}[4]\ \id{voff}[4]$.\\
  365.  This is the general format which allows all of the parameters of the
  366. \str{GF} file format, including vertical escapement.
  367. \end{description}
  368.  The \id{flag} parameter is the flag byte. The parameter \id{pl}
  369. (packet length) contains the offset of the byte following this
  370. character descriptor, with respect to the beginning of the \id{tfm}
  371. width parameter. This is given so a \str{PK} reading program can,
  372. once it has read the flag byte, packet length, and character code
  373. (\id{cc}), skip over the character by simply reading this many more
  374. bytes. For the two short forms of the character preamble, the last
  375. two bits of the flag byte should be considered the two
  376. most-significant bits of the packet length. For the short format, the
  377. true packet length might be calculated as
  378. $(\id{flag} \bmod 4)\cdot 256+\id{pl}$; for the short
  379. extended format, it might be calculated as
  380. $(\id{flag} \bmod 4)\cdot 65536+\id{pl}$.
  381. The $w$ parameter is the width and the $h$ parameter is the height in
  382. pixels of the minimum bounding box. The \id{dx} and \id{dy}
  383. parameters are the horizontal and vertical escapements, respectively.
  384. In the short formats, \id{dy} is assumed to be zero and \id{dm} is
  385. \id{dx} but in pixels; in the long format, \id{dx} and \id{dy} are
  386. both in pixels multiplied by $2^{16}$. The \id{hoff} is the
  387. horizontal offset from the upper left pixel to the reference pixel;
  388. the \id{voff} is the vertical offset. They are both given in pixels,
  389. with right and down being positive. The reference pixel is the pixel
  390. that occupies the unit square in \MF; the \MF\ reference point is the
  391. lower left hand corner of this pixel. (See the example below.)
  392. \medbreak
  393. \TeX\ requires all characters that have the same character codes
  394. modulo 256 to have also the same \id{tfm} widths and escapement
  395. values. The \str{PK} format does not itself make this a requirement,
  396. but in order for the font to work correctly with the \TeX\ software,
  397. this constraint should be observed. (The standard version of \TeX\
  398. cannot output character codes greater than 255, but extended versions
  399. do exist.)
  400. Following the character preamble is the raster information for the
  401. character, packed by run counts or by bits, as indicated by the flag
  402. byte. If the character is packed by run counts and the required
  403. number of nybbles is odd, then the last byte of the raster
  404. description should have a zero for its least significant nybble.
  405. \subsection{An example character}
  406. As an illustration of the \str{PK} format, the character \char4\ from
  407. the font {\tt amr10\/} at 300 dots per inch will be encoded. This
  408. character was chosen because it illustrates some of the borderline
  409. cases. The raster for the character is shown in
  410. figure~\ref{fig:pk-char-pic}.
  411.  \begin{figure*}[tb]
  412. \begin{paintletter}
  413. &  ********************
  414. &  ********************
  415. &  ********************
  416. &  ********************
  417. &  **                **
  418. &  **                **
  419. &  **                **
  420. &    **            **  
  421. &    **            **  
  422. &    **            **  
  423. &    ****************  
  424. &    ****************  
  425. &    ****************  
  426. &    ****************  
  427. &    **            **  
  428. &    **            **  
  429. &    **            **  
  430. &  **                **
  431. &  **                **
  432. &  **                **
  433. &  ********************
  434. &  ********************
  435. &  ********************
  436. &+ ********************
  437. \end{paintletter}
  438. \caption{Character \char4{} of {\tt amr10} (the row numbers are
  439.          chosen for convenience, and are not \protect\MF's row numbers.)}
  440. \label{fig:pk-char-pic}
  441. \end{figure*}
  442.  The width of the minimum bounding box for this character is 20; its
  443. height is 29. The `+' represents the reference pixel; notice how it
  444. lies outside the minimum bounding box. The \id{hoff} value is $-2$,
  445. and the \id{voff} is~28.
  446. The first task is to calculate the run counts and repeat counts. The repeat
  447. counts are placed at the first transition (black to white or white to black)
  448. in a row, and are enclosed in brackets. White counts are enclosed in
  449. parentheses. It is relatively easy to generate the counts list:
  450.  \begin{center}
  451.  82 [2] (16) 2 (42) [2] 2 (12) 2 (4) [3]\\
  452.  16 (4) [2] 2 (12) 2 (62) [2] 2 (16) 82\\
  453.  \end{center}
  454.  Note that any duplicated rows that are not all white or all black
  455. are removed before the run counts are calculated. The rows thus
  456. removed are rows 5, 6, 10, 11, 13, 14, 15, 17, 18, 23, and 24.
  457. \medbreak
  458. The next step in the encoding of this character is to calculate the
  459. optimal value of \id{dyn\_f}. The details of how this calculation is
  460. done are not important here; suffice it to say that there is a simple
  461. algorithm that can determine the best value of \id{dyn\_f} in one
  462. pass over the count list. For this character, the optimal value turns
  463. out to be 8 (atypically low). Thus, all count values less than or
  464. equal to 8 are packed in one nybble; those from nine to $(13-8)*16+8$
  465. or 88 are packed in two nybbles. The run encoded values now become
  466. (in hex, separated according to the above list):
  467.  \begin{center}
  468.  D9 E2 97 2 B1 E2 2 93 2 4 E3\\
  469.  97 4 E2 2 93 2 C5 E2 2 97 D9\\
  470.  \end{center}
  471.  which comes to 36 nybbles, or 18 bytes. This is shorter than the 73
  472. bytes required for the bit map, so we use the run count packing.
  473. \medbreak
  474. The short form of the character preamble is used because all of the
  475. parameters fit in their respective lengths. The packet length is
  476. therefore 18 bytes for the raster, plus eight bytes for the character
  477. preamble parameters following the character code, or 26. The \id{tfm}
  478. width for this character is 640796, or {\tt 9C71C} in hexadecimal.
  479. The horizontal escapement is 25 pixels. The flag byte is 88 hex,
  480. indicating the short preamble, the black first count, and the
  481. \id{dyn\_f} value of 8. The final total character packet, in
  482. hexadecimal, is given in figure~\ref{fig:pk-char-xd}.
  483. \begin{figure}
  484. \begin{center}
  485. \begin{tabular}{r@{\qquad}lll}
  486.    Flag byte& \tt 88\\
  487.    Packet length& \tt 1A\\
  488.    Character code& \tt 04\\
  489.    \id{tfm} width& \tt 09& \tt C7& \tt 1C\\
  490.    Horizontal escapement (pixels)& \tt 19\\
  491.    Width of bit map& \tt 14\\
  492.    Height of bit map& \tt 1D\\
  493.    Horizontal offset (signed)& \tt FE\\
  494.    Vertical offset& \tt 1C\\
  495.    Raster data& \tt D9& \tt E2& \tt 97\\
  496.    & \tt 2B& \tt 1E& \tt 22\\
  497.    & \tt 93& \tt 24& \tt E3\\
  498.    & \tt 97& \tt 4E& \tt 22\\
  499.    & \tt 93& \tt 2C& \tt 5E\\
  500.    & \tt 22& \tt 97& \tt D9\\
  501. \end{tabular}
  502. \end{center}
  503. \caption{\protect\str{PK} character packet for \char4{} of {\tt amr10}}
  504. \label{fig:pk-char-xd}
  505. \end{figure}
  506. \endinput
  507.